package com.ruoyi.space.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.space.domain.SpaceQuesDto;
import com.ruoyi.space.service.ISpaceQuesDtoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 查看问题Controller
 * 
 * @author ruoyi
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/ques")
//@CrossOrigin("*")
public class SpaceQuesDtoController extends BaseController
{
    @Autowired
    private ISpaceQuesDtoService spaceQuesDtoService;

    /**
     * 查询查看问题列表
     */
//    @RequiresPermissions("space:ques:list")
    @GetMapping("/list")
    public TableDataInfo list(SpaceQuesDto spaceQuesDto)
    {
        startPage();
        List<SpaceQuesDto> list = spaceQuesDtoService.selectSpaceQuesDtoList(spaceQuesDto);
        return getDataTable(list);
    }

    /**
     * 导出查看问题列表
     */
//    @RequiresPermissions("space:ques:export")
    @Log(title = "查看问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpaceQuesDto spaceQuesDto)
    {
        List<SpaceQuesDto> list = spaceQuesDtoService.selectSpaceQuesDtoList(spaceQuesDto);
        ExcelUtil<SpaceQuesDto> util = new ExcelUtil<SpaceQuesDto>(SpaceQuesDto.class);
        util.exportExcel(response, list, "查看问题数据");
    }

    /**
     * 获取查看问题详细信息
     */
//    @RequiresPermissions("space:ques:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(spaceQuesDtoService.selectSpaceQuesDtoById(id));
    }

    /**
     * 新增查看问题
     */
//    @RequiresPermissions("space:ques:add")
    @Log(title = "查看问题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SpaceQuesDto spaceQuesDto)
    {
        return toAjax(spaceQuesDtoService.insertSpaceQuesDto(spaceQuesDto));
    }

    /**
     * 修改查看问题
     */
//    @RequiresPermissions("space:ques:edit")
    @Log(title = "查看问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpaceQuesDto spaceQuesDto)
    {
        return toAjax(spaceQuesDtoService.updateSpaceQuesDto(spaceQuesDto));
    }

    /**
     * 删除查看问题
     */
//    @RequiresPermissions("space:ques:remove")
    @Log(title = "查看问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(spaceQuesDtoService.deleteSpaceQuesDtoByIds(ids));
    }
}
